<?php
namespace api\service;

use api\service\interfaces\IUserLogService;
use herosphp\bean\Beans;
use herosphp\core\Loader;
use herosphp\utils\AjaxResult;

Loader::import('api.service.interfaces.IUserLogService');

/**
 * 用户资金流水API服务
 * @author yangjian<yangjian102621@gmail.com>
 */
class UserLogService implements IUserLogService {

    /**
     * 获取用户交易流水，必须指定mpeid, 只允许查本mpe的会员
     * @param array $conditions
     * @param array $order
     * @param int $page
     * @param int $pagesize
     * @return AjaxResult
     */
    public function getUserLogs($conditions, $order = null, $page = 1, $pagesize = 10)
    {
        if ( isset($conditions['app_id']) ) {
            return AjaxResult::fail('不能传入app_id, 只允许查本mpe的会员');
        }
        $service = Beans::get('user.userLog.service');
        $conditions['app_id'] = getAPPID();
        $items = $service->where($conditions)->sort($order)->limit($page, $pagesize)->find();

        $resVo = AjaxResult::success(LANG('DEAL_SUCCESS'));
        $resVo->putItems($items);
        $resVo->putCount($service->count($conditions));

        return $resVo;
    }
}
